<!--贷款公示设置-->
<template>
  <div class="app-container">
    <el-form
      ref="mainForm"
      :model="formData"
      :rules="rules"
      size="mini"
      class="editForm"
      label-width="100px"
    >
      <!--表单项-->
      <el-row>
        <el-col :span="8">
          <el-form-item label="贷款银行" prop="nickName" class="car-form-item">
            <el-input v-model="formData.nickName" class="car-modal-col" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="车辆价格" prop="nickName" class="car-form-item">
            <el-input v-model="formData.nickName" class="car-modal-col" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="银行基础利率" prop="nickName" class="car-form-item">
            <el-input v-model="formData.nickName" class="car-modal-col" placeholder="请输入" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="贷款产品" prop="nickName" class="car-form-item">
            <el-input v-model="formData.nickName" class="car-modal-col" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="贷款年限" prop="nickName" class="car-form-item">
            <el-input v-model="formData.nickName" class="car-modal-col" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="衍生费用" prop="nickName" class="car-form-item">
            <el-input v-model="formData.nickName" class="car-modal-col" placeholder="请输入" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="贷款金额" prop="nickName" class="car-form-item">
            <el-input v-model="formData.nickName" class="car-modal-col" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="执行利率" prop="nickName" class="car-form-item">
            <el-input v-model="formData.nickName" class="car-modal-col" placeholder="请输入" />
          </el-form-item>
          <el-button type="primary" class="form-result" @click="addNewPartnerData()">测算</el-button>
        </el-col>
      </el-row>
    </el-form>
    <ve-table
      :columns="columns"
      :table-data="tableData"
      row-key-field-name="id"
      :border-x="true"
      :border-y="true"
      :row-style-option="rowStyleOption"
      :checkbox-option="checkboxOptipon"
    />
  </div>
</template>

<style lang="scss" scoped>
  .table-pagination {
    margin-top: 20px;
    text-align: right;
  }
  .right-btn{
    float: right;
  }
  .dialog-footer{
    text-align: center;
  }
  .car-modal-col{
    width: 280px;
  }
  .form-result{
    float: right;
    margin-right: 7px;
  }
</style>

<script>
let DB_DATA = []

export default {
  data() {
    return {
      rules: {
        name: [
          {required: true, trigger: 'blur'}
        ]
      }, // 表单校验规则
      newDialog: false, // 添加弹框
      formData: {}, // 添加表单
      listQuery: {},
      appId: sessionStorage.getItem("appId"),
      // page index
      pageIndex: 1,
      // page size
      pageSize: 10,
      dataTable: [],
      totalCount: '',
      rowStyleOption: { // 表格样式
        stripe: true, // 斑马纹
        hoverHighlight: true, // hover高亮
        clickHighlight: true // 点击行高亮
      },
      checkboxOptipon: {
        // 行选择改变事件
        selectedRowChange: ({ row, isSelected, selectedRowKeys }) => {
          console.log(row, isSelected, selectedRowKeys)
        },
        // 全选改变事件
        selectedAllChange: ({ isSelected, selectedRowKeys }) => {
          console.log(isSelected, selectedRowKeys)
        }
      },
      columns: [
        {
          field: '',
          key: 'f',
          // type=checkbox
          type: 'checkbox',
          title: '',
          width: 50,
          align: 'center'
        },
        { field: 'name', key: 'b', title: '计算字段', align: 'center' },
        { field: 'date', key: 'c', title: '公示', align: 'center' },
        { field: 'vehiclePrice', key: 'e', title: '测算结果', align: 'center' }
      ]
    }
  },
  computed: {
    // table data
    // tableData() {
    //   const { pageIndex, pageSize } = this
    //   return DB_DATA.slice((pageIndex - 1) * pageSize, pageIndex * pageSize)
    // },
    // total count
    // totalCount() {
    //   return this.tableData.length
    // }
  },
  created() {
    this.initDatabase()
  },
  methods: {
    // page number change
    pageNumberChange(pageIndex) {
      this.pageIndex = pageIndex
    },

    // page size change
    pageSizeChange(pageSize) {
      this.pageIndex = 1
      this.pageSize = pageSize
    },

    /**
     * 初始化数据
     * @date 2021-05-10
     */
    async initDatabase() {
      this.tableData = [];
      let param = {appId: await sessionStorage.getItem("appId")};
      let data = await this.$http.post('/auth/loanFormulaSetting/list/' + this.pageIndex + "/" + this.pageSize, param);
      console.log(data);
      if (data.code === 200) {
        this.tableData = data.data;
        this.totalCount = data.total;
      } else {
        this.$message({
          type: 'error',
          message: '查询失败，请刷新页面'
        });
      }
      console.log(this.tableData)
    },
    /**
     * 新增操作
     * @date 2021-05-08
     */
    async addData() {
      this.$refs['mainForm'].validate(async (valid) => {
        if (valid) {
          if (this.formData.id) {
            let data = await this.$http.post('/auth/paymentName/update', this.formData)
            console.log(data);
            if (data.code === 200) {
              this.newDialog = false;
              this.initDatabase();
            } else {
              this.$message({
                type: 'info',
                message: '操作失败，请重试'
              });
            }
          } else {
            this.formData.appId = this.appId;
            this.formData.paymentType = this.paymentType;
            let data = await this.$http.post('/auth/paymentName/add', this.formData)
            console.log(data);
            if (data.code === 200) {
              this.newDialog = false;
              this.initDatabase();
            } else {
              this.$message({
                type: 'info',
                message: '操作失败，请重试'
              });
            }
          }
        }
      })
    }
  }
}
</script>
